package com.magicborrow.views;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.magicborrow.R;

/**
 * Created by ghost on 16/4/28.
 */
public class MsgDialog extends Dialog {
    private String msg;
    private View.OnClickListener okListener;


    public MsgDialog(Context context, String msg, View.OnClickListener okListener) {
        super(context, R.style.msgDialog);
        this.msg = msg;
        this.okListener = okListener;
    }

    public void setMsg(String msg) {
        this.msg = msg;
        ((TextView) findViewById(R.id.tv_msg)).setText(msg);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_msg_dailog);
        setCanceledOnTouchOutside(true);
        ((TextView) findViewById(R.id.tv_msg)).setText(msg);
        if (okListener != null)
            findViewById(R.id.tv_ok).setOnClickListener(okListener);
        else {
            findViewById(R.id.tv_ok).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    dismiss();
                }
            });
        }
    }
}
